Thread: do {} while (0); ??

  1. #16
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Prelude
    >If you don't like my posts don't read them!!
    I don't like your posts because they're always wrong but you try to speak with authority. That's misinformation in my opinion, and it goes against everything we try to do here. Since my mission is to provide accurate information, I don't have the option of not reading your posts. Therefore, you would do well to learn what people try to teach you and apply that knowledge in the future. If not then we'll have no choice but to label you as a troll and deal with you accordingly.

    >But I can put a semicolon after a macro when I use it already.
    But does the compiler throw an error if you fail to do so? The while loop is a clever way to enforce common C syntax with macros.

    From the forum rules "and generally communicate and debate things". How can matters be debated if you have decided that you are right and I am wrong? There is nothing in the rules
    about your "mission to provide accurate information" which sound rather odd, like you are on some sort or religious crusade and that you are some self appointed infailabe god!!

    If that's the way you want to run the forum then why don't you put that in the rules so people
    can make themselves aware of this before they join (or leave as the case would be)?

  2. #17
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by esbo
    From the forum rules "and generally communicate and debate things". How can matters be debated if you have decided that you are right and I am wrong? There is nothing in the rules
    about your "mission to provide accurate information" which sound rather odd, like you are on some sort or religious crusade and that you are some self appointed infailabe god!!

    If that's the way you want to run the forum then why don't you put that in the rules so people
    can make themselves aware of this before they join (or leave as the case would be)?
    You'd be so banned if I were an admin. Stop trolling around giving incorrect information. The C standard is a STANDARD. It's not up for debate.
    Sent from my iPadŽ

  3. #18
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I am not trolling or giving incorrect information I am just putting forward my opinion, which is what a forum is meant to be for. If it's not a forum then please make that clear so people don't
    get the wrong impression before they join. If this is a forum where people can't express a reasonable opinion then it's not for me anyway.

  4. #19
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    [off-topic]What I think they mean (and take my advice since the path you are on will lead to a banning eventually) is you say things without qualifying them with something to show you are not certain about an answer. You don't have the experience (from what posts I have seen of yours) to always post with certainty. "I think blah blah blah" is a lot better when you aren't 100% positive about an answer, than going forth with an incorrect answer.

    Also, being rude to admins is not an advisable course of action.[/off-topic]

  5. #20
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    How can matters be debated if you have decided that you are right and I am wrong? There is nothing in the rules
    It is the C language standard and its syntax which says you are wrong.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #21
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by SlyMaelstrom
    You'd be so banned if I were an admin. Stop trolling around giving incorrect information. The C standard is a STANDARD. It's not up for debate.
    Funny you should say that in that I said that "Personally I avoid using macros unless I know what they do", which is pretty similiar to your own comment:- "Of course, if you know the macro, you know what's happening". If you know what it does then it's pretty unlikely you are going to use the macro in a way which might cause a problem. I mean when you use a function it's fairly normal to find out what it does before using it, so why should it be different for macros?
    Personally I would never write a macro like that with such a loop in it, fine if you want to write your macros like that, it's no skin off my nose because I won't be using your macros anyway. One of the reasons I wouldn't do it is because it just looks weird and confusing as the original poster seems to have found. Whats wrong with just putting braces around the macro anyway?

    That's just my *opinion* though, before someone starts making out that I am trying to go against the C standard or whatever, I guess I better put such a disclaimer in my signiture to say so before someone tries to sue me!! Geezz!!

  7. #22
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by esbo
    Personally I would never write a macro like that with such a loop in it
    It's not a loop in the usual sense, it is a way of controlling the scope. Please read the link that Salem posted.

    Quote Originally Posted by esbo
    Whats wrong with just putting braces around the macro anyway?
    Again, read the posted link. It's an old, fairly well-known solution to a specific problem; a "common" C idiom.

    [edit]I'll repost it for convenience:
    http://c-faq.com/cpp/multistmt.html
    [/edit]

    If you're unfamiliar with it, it is beneficial to become familiar with it.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #23
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Dave_Sinkula
    It's not a loop in the usual sense, it is a way of controlling the scope. Please read the link that Salem posted.

    Again, read the posted link. It's an old, fairly well-known solution to a specific problem; a "common" C idiom.

    [edit]I'll repost it for convenience:
    http://c-faq.com/cpp/multistmt.html
    [/edit]

    If you're unfamiliar with it, it is beneficial to become familiar with it.
    Well to be honest I, as a rule, don't use macros, I don't see a real need for them, the only time I ever used them was to make some existing code very difficult to read ( end of project and redundancies looming), and even then it doesn't take too long to decipher the macros.
    Anyway as I said the 'problem' in the link you supplied, *seems* to me to be easilly solved by the suitable use of braces {}.
    But as I said I don't use macros so I don't even need to go there. If you want to use macros, good luck to you, I don't care because it's not my code and I will never read it!!
    You see I don't need to know the solution because I don't have the problem in the first place!!

  9. #24
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by esbo
    Anyway as I said the 'problem' in the link you supplied, *seems* to me to be easilly solved by the suitable use of braces {}.
    No, it doesn't. Try reading it again.

    [edit]
    Quote Originally Posted by esbo
    Well to be honest I, as a rule, don't use macros
    And as a guideline, neither do I. This type of situation is one that goes against the guideline.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #25
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Dave_Sinkula
    No, it doesn't. Try reading it again.

    [edit]And as a guideline, neither do I. This type of situation is one that goes against the guideline.
    I have tried to read it a few times but it seems nonsense when I can write this code
    which seems to cover every situation.


    Code:
    include <stdio.h>
    #include <conio.h>
    
    #define FBB(x)  {printf("\nMACRO LINE 1 %d n", x); printf("\nMACRO LINE 2 %d n", x);}
    
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    
    {
        int num[10];
        int i= 0, cnt=0;
    	printf("\n START");
    	FBB(0)
    	printf("\nBEFORE IF");
    	if (1) FBB(0)
    	else print("\ndoh!!");
    	printf("\nAFTER IFF");
    	FBB(0)
    	printf("\npast");
    	
        return 0;
    }

  11. #26
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    But your code doesn't force a trailing semicolon, which was the whole point.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #27
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    People are used to ending statements with a semi-colon (e.g FBB(0);, not FBB(0)).

    Of course, the whole "start every printf() with a newline instead of ending it with one" is unorthodox in itself, so maybe you're just some mutant programmer.

    And why are you still using K&R syntax for function declarations? That's a good 15 years out of date now.

    And why include a non-standard header file such as conio.h? Especially when it's not even needed in your program.
    Last edited by itsme86; 09-12-2006 at 11:23 AM.
    If you understand what you're doing, you're not learning anything.

  13. #28
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    And why are you still using K&R syntax for function declarations? That's a good 15 years out of date now.
    I mentioned that already in another thread, but apparently esbo doesn't care because it works. Seriously, esbo, that is pre-ANSI C. You should use the new style.
    Of course, the whole "start every printf() with a newline instead of ending it with one" is unorthodox in itself, so maybe you're just some mutant programmer.
    I mentioned that too. esbo "always does that". esbo, why do you think there's a puts function that prints a newline after the string but no sput function that prints a newline before?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #29
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by esbo
    If that's the way you want to run the forum then why don't you put that in the rules so people can make themselves aware of this before they join (or leave as the case would be)?
    FYI, you're aware of it now so you can leave.
    If you understand what you're doing, you're not learning anything.

  15. #30
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by dwks
    But your code doesn't force a trailing semicolon, which was the whole point.

    Why would I want to force a trailing semi colon?
    Use semicolons if you want to it makes no difference!!


    Code:
    #include <stdio.h>
    #include <conio.h>
    
    #define FBB(x)  {printf("\nMACRO LINE 1 %d n", x); printf("\nMACRO LINE 2 %d n", x);}
    
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    
    {
        int num[10];
        int i= 0, cnt=0;
    	printf("\n START");
    	FBB(0);
    	printf("\nBEFORE IF");
    		if (1) FBB(0);
    	else print("\ndoh!!");
    	printf("\nAFTER IFF");
    	FBB(0);
    	printf("\npast");
    	
        return 0;
    }
    Last edited by esbo; 09-12-2006 at 11:36 AM.

Popular pages Recent additions subscribe to a feed